package com.stress.testing.plugin.java.jdbc.sql.parser;

import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor;

public class TableNameVisitor extends MySqlOutputVisitor {
    private String tableNamePrefix;

    public TableNameVisitor(Appendable appender, String tableNamePrefix) {
        super(appender);
        this.tableNamePrefix = tableNamePrefix;
    }

    @Override
    public boolean visit(SQLExprTableSource x) {
        SQLName table = (SQLName) x.getExpr();
        String tableName = table.getSimpleName();
        if (tableName.startsWith(tableNamePrefix)) {
            return true;
        }

        print0(tableNamePrefix + tableName.toUpperCase());
        return true;
    }
}
